<?xml version="1.0"?>
<rss version="2.0">
  <channel><title>PHP Setup</title><link>http://caudium.net//space/documentation/PHP Setup</link><description>&lt;h2&gt;&#xD;
1. Introduction&amp;nbsp;&#xD;
&lt;/h2&gt;&#xD;
There are two recommended ways to run PHP with Caudium. Each way has its advantages and drawbacks.&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
PHP can be run:&amp;nbsp;&#xD;
&lt;br&gt;&#xD;
&lt;ul&gt;&#xD;
	&lt;li style="min-height: 1.2em;"&gt;&#xD;
		As a CGI, using Caudium Uniscript module.&#xD;
	&lt;/li&gt;&#xD;
	&lt;li style="min-height: 1.2em;"&gt;&#xD;
		As a FastCGI, using Caudium FastUniscript module.&#xD;
	&lt;/li&gt;&#xD;
&lt;/ul&gt;&#xD;
&lt;br&gt;&#xD;
Both methods are similar, simply compile your PHP with support for FastCGI to use the second option and replace FastUniscript in the instructions.&amp;nbsp; A third method using PHP as a module is&amp;nbsp;not supported anymore&amp;nbsp;due to PHP bugs. Read further for more information&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
&lt;h2&gt;&#xD;
2. PHP using Uniscript&#xD;
&lt;/h2&gt;&#xD;
&lt;h3&gt;&#xD;
2.1. Introduction to Uniscript Mode&#xD;
&lt;/h3&gt;&#xD;
&lt;br&gt;&#xD;
Uniscript mode is in fact using PHP in CGI mode. Caudium has a module named&amp;nbsp;Universal Script Parser&amp;nbsp;that allows you to wrap any special extensions inside a webserver to a&amp;nbsp;CGI. Eg&amp;nbsp;.php&amp;nbsp;to&amp;nbsp;/usr/local/bin/php. This is the way PHP will be run.&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
&lt;h3&gt;&#xD;
2.2. Drawbacks&#xD;
&lt;/h3&gt;&#xD;
&lt;ul&gt;&#xD;
	&lt;li&gt;&#xD;
		A PHP interpreter is forked on each page called. This can be ressource consuming.&#xD;
	&lt;/li&gt;&#xD;
	&lt;li&gt;&#xD;
		Some PHP options and some security options must be considered. See the&amp;nbsp;PHP manual&amp;nbsp;about PHP install as a CGI manual.&#xD;
	&lt;/li&gt;&#xD;
&lt;/ul&gt;&#xD;
&lt;h3&gt;&#xD;
2.3. Benefits&#xD;
&lt;/h3&gt;&#xD;
&lt;ul&gt;&#xD;
	&lt;li&gt;&#xD;
		Since it is in a CGI, when PHP crashes Caudium doesn't :).&#xD;
	&lt;/li&gt;&#xD;
	&lt;li&gt;&#xD;
		You can run PHP as a user different than Caudium.&#xD;
	&lt;/li&gt;&#xD;
	&lt;li&gt;&#xD;
		You can give specify limitation on the size of processes and resources usage.&#xD;
	&lt;/li&gt;&#xD;
	&lt;li&gt;&#xD;
		You can have several PHP interpreters with different&amp;nbsp;php.ini&amp;nbsp;files and compilations.&#xD;
	&lt;/li&gt;&#xD;
&lt;/ul&gt;&#xD;
&lt;h3&gt;&#xD;
2.4. Software requirements&#xD;
&lt;/h3&gt;&#xD;
Before installing PHP4 support as a CGI for Caudium, you will need the following:&#xD;
&lt;ul&gt;&#xD;
	&lt;li&gt;&#xD;
		An OS supported by PHP4 and Caudium.&#xD;
	&lt;/li&gt;&#xD;
	&lt;li&gt;&#xD;
		Caudium installed (you&amp;nbsp;don't&amp;nbsp;need Pike development headers).&#xD;
	&lt;/li&gt;&#xD;
	&lt;li&gt;&#xD;
		PHP4 sources (we recommend PHP 4.3.2RC2)&#xD;
	&lt;/li&gt;&#xD;
	&lt;li&gt;&#xD;
		An ANSI C compiler and all libraries needed for compiling PHP.&#xD;
	&lt;/li&gt;&#xD;
&lt;/ul&gt;&#xD;
&lt;br&gt;&#xD;
We assume that you have successfully installed Pike and Caudium on your machine.&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
&lt;h3&gt;&#xD;
2.5. Compilation and installation of PHP&#xD;
&lt;/h3&gt;&#xD;
&lt;br&gt;&#xD;
NOTE: in this example, we assume that we will install all PHP in&amp;nbsp;/usr/local/php-4.3.2RC-cgi/.&#xD;
&lt;br&gt;&#xD;
Extract PHP4 source somewhere and do the following :&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
&amp;nbsp;&#xD;
&lt;div class="code"&gt;&lt;pre&gt;&lt;pre&gt;&#xD;
 $ cd php-4.3.2RC2&#xD;
 $ ./configure --prefix=/usr/local/php-4.3.2RC-cgi/ --enable-force-cgi-redirect &amp;#92;&#xD;
               --enable-discard-path --enable-fastcgi --without-pear --enable-safe-mode &amp;#92;&#xD;
               --enable-sigchild --enable-magic-quotes --disable-rpath &amp;#92;&#xD;
               --with-other-php-options&#xD;
 $ make&#xD;
&lt;/pre&gt;&lt;/pre&gt;&lt;/div&gt;
&#xD;
Now the PHP interpreter is fully compiled and can be installed.&#xD;
&lt;br&gt;&#xD;
&#xD;
	&lt;br&gt;&#xD;
&lt;div class="code"&gt;&lt;pre&gt;&lt;pre&gt;&#xD;
 $ make install&#xD;
&lt;/pre&gt;&lt;/pre&gt;&lt;/div&gt;
&#xD;
	&lt;br&gt;&#xD;
	&lt;br&gt;&#xD;
&lt;h3&gt;&#xD;
2.6. Configuring Caudium&#xD;
&lt;/h3&gt;&#xD;
Log into the graphical configuration interface and go to the virtual server where you want to add PHP support.&amp;nbsp;&amp;nbsp;&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
Click on &amp;quot;Add Module&amp;quot;, locate and add PATH_INFO support module and Universal Script parser module.&amp;nbsp;&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
Then configure the Universal Script Parser module with the following options :&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
&lt;ul&gt;&#xD;
	&lt;li&gt;&#xD;
		interpreter path :&amp;nbsp;/usr/local/php-4.3.2RC-cgi/bin/php&amp;nbsp;or the place where where you have installed php. &amp;nbsp;&#xD;
	&lt;/li&gt;&#xD;
	&lt;li&gt;&#xD;
		script extensions :&amp;nbsp;php&amp;nbsp;or comma separated extensions you'd like to handle with that php cgi. &amp;nbsp;&#xD;
	&lt;/li&gt;&#xD;
&lt;/ul&gt;&#xD;
&lt;br&gt;&#xD;
Note that you can configure the&amp;nbsp;&lt;i&gt;Run script as&lt;/i&gt;&amp;nbsp;option if you want to run php with a different user than default:nobody.&amp;nbsp;&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
Then create a test page with :&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
&lt;div class="code"&gt;&lt;pre&gt;&lt;pre&gt;&#xD;
&amp;lt;? phpinfo(); ?&amp;gt;&#xD;
&lt;/pre&gt;&lt;/pre&gt;&lt;/div&gt;
&#xD;
&lt;br&gt;&#xD;
&amp;nbsp;&amp;nbsp;&#xD;
&lt;br&gt;&#xD;
Then you will get the PHP Info page.&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
&lt;h3&gt;&#xD;
2.7. Hints&#xD;
&lt;/h3&gt;&#xD;
To use sessions in CGI mode you will need to save them on disk instead of memory. To do that, you will need to change/add option in you&amp;nbsp;/usr/local/php-4.3.2RC-cgi/lib/php.ini:&#xD;
&lt;br&gt;&#xD;
&amp;nbsp;&#xD;
&lt;div class="code"&gt;&lt;pre&gt;&lt;pre&gt;&#xD;
&amp;#91;Session]&#xD;
; Handler used to store/retrieve data.&#xD;
session.save_handler = files&#xD;
&#xD;
; Argument passed to save_handler.  In the &lt;font color=black&gt;case&lt;/font&gt; of files, this is the path&#xD;
; where data files are stored. Note&lt;font color=black&gt;:&lt;/font&gt; Windows users have to change this &#xD;
; variable in order to use PHP's session &lt;b&gt;&lt;font color=darkgreen&gt;function&lt;/font&gt;&lt;/b&gt;&lt;b&gt;&lt;font color=darkbrown&gt;s.&lt;/font&gt;&lt;/b&gt;&#xD;
; As of PHP 4.0.1, you can define the path as:&#xD;
;     session.save_path = &lt;i&gt;&lt;font color=darkred&gt;"N;/path"&lt;/font&gt;&lt;/i&gt;&#xD;
; where N is an &lt;b&gt;&lt;font color=darkgreen&gt;int&lt;/font&gt;&lt;/b&gt;&lt;b&gt;&lt;font color=darkbrown&gt;eger.&lt;/font&gt;&lt;/b&gt;  Instead of storing all the session files in &#xD;
; /path, what this will &lt;b&gt;&lt;font color=darkblue&gt;do&lt;/font&gt;&lt;/b&gt; is use subdirectories N-levels deep, and &#xD;
; store the session data in those directories.  This is useful &lt;b&gt;&lt;font color=darkblue&gt;if&lt;/font&gt;&lt;/b&gt; you &#xD;
; or your OS have problems with lots of files in one directory, and is &#xD;
; a more efficient layout &lt;b&gt;&lt;font color=darkblue&gt;for&lt;/font&gt;&lt;/b&gt; servers that handle lots of sessions.&#xD;
; NOTE 1: PHP will not create this directory structure automatically.&#xD;
;         You can use the script in the ext/session dir &lt;b&gt;&lt;font color=darkblue&gt;for&lt;/font&gt;&lt;/b&gt; that purpose.&#xD;
; NOTE 2: See the section on garbage collection below &lt;b&gt;&lt;font color=darkblue&gt;if&lt;/font&gt;&lt;/b&gt; you choose to&#xD;
;         use subdirectories &lt;b&gt;&lt;font color=darkblue&gt;for&lt;/font&gt;&lt;/b&gt; session storage&#xD;
session.save_path = /var/sessions&#xD;
&#xD;
; Whether to use cookies.&#xD;
session.use_cookies = 1&#xD;
&#xD;
; This option enables administrators to make their users invulnerable to&#xD;
; attacks which involve passing session ids in URLs; defaults to 0.&#xD;
; session.use_only_cookies = 1&#xD;
&#xD;
; Name of the session (used as cookie name).&#xD;
session.name = PHPSESSID&#xD;
&#xD;
; Initialize session on request startup.&#xD;
session.auto_start = 0&#xD;
&#xD;
; Lifetime in seconds of cookie or, if 0, until browser is restarted.&#xD;
session.cookie_lifetime = 0&#xD;
&#xD;
; The path &lt;b&gt;&lt;font color=darkblue&gt;for&lt;/font&gt;&lt;/b&gt; which the cookie is valid.&#xD;
session.cookie_path = /&#xD;
&#xD;
; The domain &lt;b&gt;&lt;font color=darkblue&gt;for&lt;/font&gt;&lt;/b&gt; which the cookie is valid.&#xD;
session.cookie_domain =&#xD;
&#xD;
; Handler used to serialize data.  php is the standard serializer of PHP.&#xD;
session.serialize_handler = php&#xD;
&#xD;
; Define the probability that the 'garbage collection' process is started&#xD;
; on every session initialization.&#xD;
; The probability is calculated by using gc_probability/gc_divisor,&#xD;
; e.g. 1/100 means there is a 1% chance that the GC process starts&#xD;
; on each request.&#xD;
&#xD;
session.gc_probability = 1&#xD;
session.gc_divisor     = 100&#xD;
&#xD;
; After this number of seconds, stored data will be seen as 'garbage' and&#xD;
; cleaned up by the garbage collection process.&#xD;
session.gc_maxlifetime = 1440&#xD;
&#xD;
; NOTE: If you are using the subdirectory option &lt;b&gt;&lt;font color=darkblue&gt;for&lt;/font&gt;&lt;/b&gt; storing session files&#xD;
;       (see session.save_path above), then garbage collection does *not*&#xD;
;       happen automatically.  You will need to do your own garbage &#xD;
;       collection through a shell script, cron entry, or some other method. &#xD;
;       For example, the following script would is the equivalent of&#xD;
;       setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes):&#xD;
;          cd /path/to/sessions; find -cmin +24 | xargs rm&#xD;
; PHP 4.2 and less have an undocumented feature/bug that allows you to&#xD;
; to initialize a session variable in the global scope, albeit register_globals&#xD;
; is disabled.  PHP 4.3 and later will warn you, if this feature is used.&#xD;
; You can disable the feature and the warning seperately. At this time,&#xD;
; the warning is only displayed, if bug_compat_42 is enabled.&#xD;
&#xD;
session.bug_compat_42 = 1&#xD;
session.bug_compat_warn = 1&#xD;
&#xD;
; Check HTTP Referer to invalidate externally stored URLs containing ids.&#xD;
; HTTP_REFERER has to contain this substring &lt;b&gt;&lt;font color=darkblue&gt;for&lt;/font&gt;&lt;/b&gt; the session to be&#xD;
; considered as valid.&#xD;
session.referer_check =&#xD;
&#xD;
; How many bytes to read from the file.&#xD;
session.entropy_length = 12&#xD;
&#xD;
; Specified here to create the session id.&#xD;
session.entropy_file = /dev/urandom&#xD;
&#xD;
;session.entropy_length = 16&#xD;
&#xD;
;session.entropy_file = /dev/urandom&#xD;
; Set to {nocache,private,public,} to determine HTTP caching aspects&#xD;
; or leave this empty to avoid sending anti-caching headers.&#xD;
session.cache_limiter = nocache&#xD;
&#xD;
; Document expires after n minutes.&#xD;
session.cache_expire = 180&#xD;
&#xD;
; trans sid support is disabled by default.&#xD;
; Use of trans sid may risk your users security. &#xD;
; Use this option with caution.&#xD;
; - User may send URL contains active session ID&#xD;
;   to other person via. email/irc/etc.&#xD;
; - URL that contains active session ID may be stored&#xD;
;   in publically accessible computer.&#xD;
; - User may access your site with the same session ID&#xD;
;   always using URL stored in browser's history or bookmarks.&#xD;
session.use_trans_sid = 0&#xD;
&lt;/pre&gt;&lt;/pre&gt;&lt;/div&gt;
&#xD;
&lt;p&gt;&#xD;
&#xD;
Please check your PHP manual for more information about this parameters.&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
&lt;h2&gt;&#xD;
3. PHP as a module (not supported anymore)&#xD;
&lt;/h2&gt;&#xD;
Some documentation (eg the one from&amp;nbsp;PHP) may give some instructions for building and using PHP as a module. &amp;nbsp; However, embedded PHP does not work well in a threaded environment. It neither work on Apache 2.0 and this won't be fixed in the forseeable future (a few years at least&amp;nbsp;according to Rasmus LERDORF) &amp;nbsp;  While this may behave correctly while running Caudium unthreaded, this usage is not supported by the Caudium group anymore and won't be until this issue is not fixed on the&amp;nbsp;PHP side.&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
Please use the CGI/FastCGI modes instead.&amp;nbsp;&#xD;
&lt;br&gt;&#xD;
&lt;br&gt;&#xD;
&lt;h2&gt;&#xD;
4. Conclusion&#xD;
&lt;/h2&gt;&#xD;
At the time of writing this document, the most stable way to use PHP is the CGI one. &amp;nbsp;It is up to you to decide between stability and speed. But the difference between them is not so big, only stability may be an issue.&#xD;
</description><generator>Fins 0.9.7</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs></channel>
</rss>
